package com.xiyoukt.springboot.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

@Component
public class AsyncTask {

    private Logger log = LoggerFactory.getLogger(ScheduleTask.class);

    // 异步调用是不能直接返回数据的
    @Async
    public String task1() throws InterruptedException {
        log.info("task1 runing");
        Thread.sleep(10000);
        return "ok";
    }

    @Async
    public Future<String> task2() throws InterruptedException {
        log.info("task1 runing");
        Thread.sleep(10000);
        AsyncResult<String> future = new AsyncResult<>("OK");
        return future;
    }

}
